<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>去除字符串出现次数最少得字符</title>
  </head>
  <body></body>
</html>
<script>
  function removeStrChars(str) {
    const charCont = {};
    //    统计字符出现次数
    for (let char of str) {
      charCont[char] = (charCont[char] || 0) + 1;
    }
    //    找出现次数最少的次数
    let minCont = Infinity;
    for (let count of Object.values(charCont)) {
      minCont = Math.min(minCont, count);
    }

    let result = "";
    for (let char of str) {
      if (charCont[char] > minCont) {
        result += char;
      }
    }

    return result;
  }
  // 打印
  console.log(removeStrChars("aaabbbccee"));
</script>
